const { app, BrowserWindow } = require('electron');
const path = require('path');

(async () => {
    const isDev = (await import('electron-is-dev')).default;

    function createWindow() {
        const mainWindow = new BrowserWindow({
            width: 800,
            height: 600,
            webPreferences: {
                nodeIntegration: true,
                contextIsolation: false,// 禁用上下文隔离
                enableRemoteModule: true // 如果需要使用 remote 模块
            }
        });

        const urlLocation = isDev ? 'http://localhost:3000' : 'dummyurl';
        mainWindow.loadURL(urlLocation);

        if (isDev) {
            mainWindow.webContents.openDevTools();
        }
    }

    app.whenReady().then(createWindow);

    app.on('window-all-closed', () => {
        if (process.platform !== 'darwin') {
            app.quit();
        }
    });

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow();
        }
    });
})();